package huawei.js2025;

import java.util.Scanner;

/**
 * 约瑟夫问题
 */
public class Question23 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();

        int[] nums = new int[N];
        for (int i = 0; i < N; i++) {
            nums[i] = sc.nextInt();
        }

        int M = sc.nextInt();

        int cur = 0;
        while (N > 0) {
            int i = Math.max(((M + cur) % N) - 1, 0);
            M = nums[i];
            cur = i;
            for (int j = i + 1; j < N; j++) {
                nums[j - 1] = nums[j];
            }
            nums[N - 1] = M;

            N -= 1;
        }

        for (int i = nums.length - 1; i >= 0; i--) {
            if (i != 0) {
                System.out.print(nums[i] + ",");
            } else {
                System.out.print(nums[i]);
            }
        }
        System.out.println();


    }
}
